# coding: utf-8
""" ndarray数组的转置和轴对换
"""

import numpy as np
from helpers import (
					print2, 
					print_20_,
					)

print_20_()
print2("ndarray数组的转置和轴对换")
k = np.arange(9)
print2("print(k) ->", k)
m = k.reshape((3,3))
print2("print(m) ->", m, "# 改变数组的shape复制生成2维的，每个维度长度为3的数组")
print2("print(m.T) ->", m.T, "# 转置(矩阵)数组：T属性")
print2("print(np.dot(m, m.T)) ->", np.dot(m, m.T), "# numpy.dot点乘, 计算矩阵的内积 xTx")

print_20_()
k = np.arange(8).reshape(2,2,2)
print2("print(k) ->", k)
m = k.transpose((1,0,2))
print2("print(m) ->", m, "# 轴变换 transpose 参数:由轴编号组成的元组, m[y][x][z] = k[x][y][z]")
print2("print(m[0][1][0]) ->",m[0][1][0])
m = k.swapaxes(0,1)
print2("print(m) ->", m, "# 轴交换 swapaxes (axes：轴),将第一个轴和第二个轴交换 m[y][x][z] = k[x][y][z]")
print2("print(m[0][1][0]) ->",m[0][1][0])
print_20_()

m = np.arange(9).reshape((3,3))
print2("print(m) ->", m)
print2("print(m.swapaxes(1,0)) ->", m.swapaxes(1,0))
